﻿using PLCS.App.Shared.Events;

namespace PLCS.App.Shared.ViewModels.Common;

public class MsgBoxViewModel : BindableBase, IDialogAware
{
    private string _icon;

    public string Icon
    {
        get { return _icon; }
        set { SetProperty(ref _icon, value); }
    }

    private string _msg;

    public string Msg
    {
        get { return _msg; }
        set { SetProperty(ref _msg, value); }
    }

    private bool _btnHide;

    public event Action<IDialogResult> RequestClose;

    public bool BtnHide
    {
        get { return _btnHide; }
        set { SetProperty(ref _btnHide, value); }
    }

    public string Title { get; set; }

    public bool CanCloseDialog()
    {
        return true;
    }

    public void OnDialogClosed()
    {
    }

    public void OnDialogOpened(IDialogParameters parameters)
    {
        if (parameters.ContainsKey("Value"))
        {
            var model = parameters.GetValue<ShowMsgBoxModel>("Value");
            Icon = model.Icon;
            Msg = model.Msg;
            BtnHide = model.BtnHide;
            Title = model.Title;
        }
    }

    public DelegateCommand SaveCommand { get; }

    public DelegateCommand CancelCommand { get; }

    public MsgBoxViewModel()
    {
        SaveCommand = new DelegateCommand(Save);
        CancelCommand = new DelegateCommand(Cancel);
    }

    protected void Cancel()
    {
        RequestClose?.Invoke(new DialogResult(ButtonResult.No));
    }

    protected void Save()
    {
        RequestClose?.Invoke(new DialogResult(ButtonResult.Yes));
    }
}